package no.rmz.chez.players;


import no.rmz.chez.movementGeneration.MinimaxMoveGenerator;
import no.rmz.chez.chess.board.Color;
import no.rmz.chez.evaluators.BoardEvaluator;
import no.rmz.genetics.Genetic;

/**
 * This class implements a naive minimax optimizing chessplayer.
 * Also serves as a prototypical example of a parameterizable
 * algorithm that can be optimized using genetic programming.
 * 
 * XXX Is missing the thing doing game tree branch joining (or whatever
 *     it is called in  gaming parlance).
 */
@Genetic
public class MinimaxPlayer extends ChessPlayer {

   
    final int lookahead;
    
    /**
     * Create a new instance of a player with a specific color..
     * @param c the color of the player.
     * @param d the depth to search the game tree.
     * @param e a board evaluator, used to find
     *          the goodness of the boards.
     */
    public MinimaxPlayer(
            final Color c,
            final int d,
            final BoardEvaluator e) {
        super(new MinimaxMoveGenerator(d, e),c);
        lookahead = d;
    }

    /**
     * Create a new instance of a player without a specific color.
     * @param d the depth to search the game tree.
     * @param e a board evaluator, used to find
     *          the goodness of the boards.
     */
    public MinimaxPlayer(
            final int d,
            final BoardEvaluator e) {
        this(null, d, e);
    }

 

    /**
     * Disable checking of terminal positions. THis is
     * useful for debugging but not for actual play.
     */
    public void doDisableTerminalCheck() {
        ((MinimaxMoveGenerator)getGen()).doDisableTerminalCheck();
    }

    /**
     *  Overriding standard output for debugging purposes.
     *  @return a string describing the player, mostly for debugging purposes
     */
    @Override
    public final String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("[MinimaxPlayer id = ").append(hashCode()).append(" lookahead = ").append(lookahead).append("]");
        return sb.toString();
    }
}
